package com.evaluation_system.mapper;

import com.evaluation_system.pojo.DTO.UploaderPageQueryDTO;
import com.evaluation_system.pojo.entity.Uploader;
import com.evaluation_system.pojo.entity.UploaderFile;
import com.evaluation_system.pojo.entity.saveFileInfo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import com.evaluation_system.pojo.DTO.FilePageQueryDTO;

@Mapper
public interface UploaderMapper {
    @Select("SELECT id FROM uploader WHERE username = #{username}")
    Integer getId(String username);

    @Insert("INSERT INTO file(uploader_id,summary,file_path,file_name,secret_key,secret_iv) VALUES (#{uploaderId},#{summary},#{filePath},#{fileName},#{secretKey},#{secretIV})")
    void insertFile(saveFileInfo saveFileInfo);


    Page<Uploader> pageQuery(UploaderPageQueryDTO uploaderPageQueryDTO);

    @Insert("INSERT INTO uploader(username,password,truth) VALUES (#{username},#{password},#{truth})")
    void insert(Uploader uploader);

    void update(Uploader uploader);

    @Delete("DELETE FROM uploader WHERE id = #{id}")
    void deleteById(Integer id);

    @Select("SELECT id FROM file ORDER BY id DESC LIMIT 1;")
    Integer getFileID(String fileName);

    @Update("UPDATE file SET hash1 = #{transactionHash},is_checked=0 WHERE id = #{fileId}")
    void saveHash1(
        @Param("fileId") Integer fileId,
        @Param("transactionHash") String transactionHash
    );

    Page<saveFileInfo> getFile(FilePageQueryDTO filePageQueryDTO);

    @Select("SELECT * FROM uploader WHERE id = #{userId}")
    Uploader SelectById(Integer userId);

    @Select("SELECT uploader_id FROM file WHERE file_name = #{filename}")
    Integer FilenameByUploaderId(String filename);


    void updateFile(saveFileInfo saveFileInfo);

    @Delete("DELETE FROM score WHERE file_id = #{fileId}")
    void deleteByfileId(int fileId);
}
